package com.jamie.utils;

import java.io.File;
import java.io.UnsupportedEncodingException;

public class PathUtils {
    public static void main(String args[]) {
        String userDir = System.getProperty("user.dir");
        System.out.println(userDir + "\\src\\main\\");
    }

    public static String getMyDIR() {//获取当前类文件的绝对路径
        String jarWholePath = PathUtils.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        try {
            //保险起见，将路径进行decode转码
            jarWholePath = java.net.URLDecoder.decode(jarWholePath, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            System.out.println(e.toString());
        }
        //获取jar包的上级目录
        String jarPath = new File(jarWholePath).getParentFile().getAbsolutePath();
        return jarPath;
    }
}

